home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Mac OS X Throbber / Source / GDeviceUtils.h < prev    next >
Text File  |  2000-06-23  |  5KB  |  306 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    GDeviceUtils.h
  4. #
  5. #    by Eric Traut
  6. #
  7. ------------------------------------------------------------------------------*/
  8.  
  9. #include <Types.h>
  10. #include <QDOffscreen.h>
  11. #include <Displays.h>
  12.  
  13. // GraphicSurface
  14. // This class encapsulates a blitting surface, specifying
  15. // its base pointer, depth, dimensions and rowBytes values.
  16. // The actual surface may be real or virtual. In many ways,
  17. // it's comparable to a GWorld in the Mac toolbox.
  18. class GraphicSurface
  19. {
  20.     public:
  21.         GraphicSurface();
  22.         
  23.         void
  24.         ExtractRealDeviceInfo(
  25.             GDHandle            inGDevice);
  26.         
  27.         UInt16
  28.         GetRowBytes() const
  29.         {
  30.             return mRowBytes;
  31.         }
  32.         
  33.         UInt8 *
  34.         GetPixelDataPtr() const
  35.         {
  36.             return mPixelData;
  37.         }
  38.         
  39.         UInt16
  40.         GetBitDepth() const
  41.         {
  42.             return mBitDepth;
  43.         }
  44.         
  45.         UInt16
  46.         GetHeight() const
  47.         {
  48.             return mHeight;
  49.         }
  50.         
  51.         UInt16
  52.         GetWidth() const
  53.         {
  54.             return mWidth;
  55.         }
  56.         
  57.         UInt32
  58.         GetBackingSize() const
  59.         {
  60.             // Allocate two extra scan lines for some slop
  61.             return GetRowBytes() * (GetHeight() + 2);
  62.         }
  63.         
  64.     private:
  65.         UInt16            mRowBytes;
  66.         UInt8 *            mPixelData;
  67.         UInt16            mBitDepth;
  68.         UInt16            mHeight;
  69.         UInt16            mWidth;
  70. };
  71.  
  72.  
  73. class VirtualGDevice;
  74.  
  75. class GraphicBlendEffect
  76. {
  77.     public:
  78.         GraphicBlendEffect()
  79.         {
  80.         }
  81.         
  82.         virtual
  83.         ~GraphicBlendEffect()
  84.         {
  85.         }
  86.  
  87.         virtual Boolean
  88.         Initialize()
  89.         {
  90.             return true;
  91.         }
  92.         
  93.         virtual void
  94.         SetEffectValue(
  95.             UInt16                inValueIndex,
  96.             double                inValue)
  97.         {
  98.             (void)inValueIndex;
  99.             (void)inValue;
  100.         }
  101.         
  102.         virtual void
  103.         BlendVirtualDevices(
  104.             const GraphicSurface &    inDestSurface,
  105.             VirtualGDevice **        inVDeviceList,
  106.             UInt32                    inVDeviceCount) = 0;
  107. };
  108.  
  109.  
  110. class SimpleBlendEffect : public GraphicBlendEffect
  111. {
  112.     public:
  113.         SimpleBlendEffect()
  114.         {
  115.         }
  116.         
  117.         virtual void
  118.         BlendVirtualDevices(
  119.             const GraphicSurface &    inDestSurface,
  120.             VirtualGDevice **        inVDeviceList,
  121.             UInt32                    inVDeviceCount);
  122. };
  123.  
  124.  
  125. class ThrobEffect : public GraphicBlendEffect
  126. {
  127.     public:
  128.         ThrobEffect()
  129.         {
  130.         }
  131.         
  132.         UInt16 *
  133.         DimVariably(
  134.             UInt16        *in,
  135.             UInt16        *out,
  136.             int            ratio,
  137.             int            count,
  138.             int            start,
  139.             int            stop);
  140.  
  141.         virtual void
  142.         BlendVirtualDevices(
  143.             const GraphicSurface &    inDestSurface,
  144.             VirtualGDevice **    inVDeviceList,
  145.             UInt32                inVDeviceCount);
  146. };
  147.  
  148.  
  149. class DontThrobEffect : public GraphicBlendEffect
  150. {
  151.     public:
  152.         DontThrobEffect()
  153.         {
  154.             mPrimaryScreenFraction = 0.0;
  155.         }
  156.         
  157.         UInt16 *
  158.         DimVariably(
  159.             UInt16        *in,
  160.             UInt16        *out,
  161.             int            ratio,
  162.             int            count,
  163.             int            start,
  164.             int            stop);
  165.  
  166.         virtual void
  167.         BlendVirtualDevices(
  168.             const GraphicSurface &    inDestSurface,
  169.             VirtualGDevice **        inVDeviceList,
  170.             UInt32                    inVDeviceCount);
  171.     
  172.         virtual void
  173.         SetEffectValue(
  174.             UInt16                inValueIndex,
  175.             double                inValue);
  176.  
  177.     private:
  178.         double            mPrimaryScreenFraction;
  179. };
  180.  
  181.  
  182. // CapturedGDevice
  183. // This class allows us to "capture" an existing GDevice (monitor).
  184. class CapturedGDevice
  185. {
  186.     public:
  187.         CapturedGDevice();
  188.         
  189.         virtual
  190.         ~CapturedGDevice();
  191.         
  192.         void
  193.         CaptureDevice(
  194.             GDHandle            inGDevice,
  195.             VirtualGDevice **    inVDeviceList,
  196.             UInt32                inVDeviceCount);
  197.         
  198.         void
  199.         UncaptureDevice();
  200.         
  201.         void
  202.         UpdateCapturedScreen();
  203.         
  204.         void
  205.         RecomputeGDHandle();
  206.         
  207.         GraphicSurface &
  208.         GetGraphicSurface()
  209.         {
  210.             return mCapturedSurface;
  211.         }
  212.         
  213.         void
  214.         SetGraphicBlendEffect(
  215.             GraphicBlendEffect *    inBlendEffect);
  216.         
  217.         void
  218.         SetGraphicBlendValue(
  219.             UInt32                    inValueIndex,
  220.             double                    inValue);
  221.         
  222.         void
  223.         SetPixelBase(
  224.             UInt8 *                inPixelBase);
  225.  
  226.         PixMapHandle
  227.         GetPixMapHandle()
  228.         {
  229.             return mGDHandle[0]->gdPMap;
  230.         }
  231.  
  232.         void
  233.         ClearCapturedScreen();
  234.  
  235.     private:
  236.         GraphicBlendEffect *    mBlendEffect;
  237.         
  238.         GraphicSurface            mCapturedSurface;
  239.         GDHandle                mGDHandle;
  240.         DisplayIDType            mDisplayID;
  241.         Boolean                    mDeviceCaptured;
  242.  
  243.         VirtualGDevice **        mVirtualDeviceList;
  244.         UInt32                    mVirtualDeviceCount;
  245. };
  246.  
  247.  
  248. // VirtualGDevice
  249. // This class allows us to create a new "virtual" GDevice, effectively
  250. // adding a monitor to the system. One VirtualGDevice (and one only)
  251. // should be designated the "primary" device. This allows us to make
  252. // use of the existing GWorld handle in the system.
  253. class VirtualGDevice
  254. {
  255.     public:
  256.         VirtualGDevice();
  257.  
  258.         virtual
  259.         ~VirtualGDevice();
  260.     
  261.         Boolean
  262.         Initialize(
  263.             CapturedGDevice &    inRealGDevice,
  264.             UInt32                inIndex);
  265.  
  266.         void
  267.         GetPreferredPosition(
  268.             Rect &                outPos)
  269.         {
  270.             outPos = mPreferredPos;
  271.         }
  272.         
  273.         void
  274.         Uninitialize();
  275.  
  276.         void
  277.         RecomputeGDHandle();
  278.  
  279.         GraphicSurface &
  280.         GetGraphicSurface()
  281.         {
  282.             return mVirtualSurface;
  283.         }
  284.  
  285.         GDHandle
  286.         GetGDHandle()
  287.         {
  288.             RecomputeGDHandle();
  289.             return mGDHandle;
  290.         }
  291.     
  292.     private:
  293.         GraphicSurface        mVirtualSurface;
  294.         Ptr                    mDeviceBacking;
  295.         Boolean                mAddedToDeviceList;
  296.         GDHandle            mGDHandle;
  297.         DisplayIDType        mDisplayID;
  298.         Rect                mPreferredPos;
  299. };
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.